const Router = require("koa-router");

const momentRouter = new Router({ prefix: "/moment" });

const {
  create,
  detail,
  list,
  update,
  remove,
  addLabels,
  fileInfo,
} = require("../controller/moment.controller.js");

const {
  verifyAuth,
  verifyPermission,
} = require("../middleware/auth.middleware");

const {
  // 判断标签是否存在
  verifyLabelExists,
} = require("../middleware/label.middleware");

// 创建动态
momentRouter.post("/", verifyAuth, create);
// 查询动态(单个)
momentRouter.get("/:momentId", detail); // 这里的 ： 是什么语法
// 查询全部动态
momentRouter.get("/", list);
// 修改动态   (1.用户必须登录/授权  2.验证登录的用户是否具备权限去修改内容)
momentRouter.patch("/:momentId", verifyAuth, verifyPermission, update);
// 删除动态
momentRouter.delete("/:momentId", verifyAuth, verifyPermission, remove);
// 给动态添加标签
momentRouter.post(
  "/:momentId/labels",
  verifyAuth,
  verifyPermission,
  verifyLabelExists,
  addLabels
);
// 动态配图服务
momentRouter.get("/images/:filename", fileInfo);

module.exports = momentRouter;
